// pages/ord_norecei/ord_norecei.js

//获取应用实例
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    sessionkey: '',
    goodslist: [],
    isdata: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({
      'sessionkey': wx.getStorageSync('sessionkey'),
      'type': options.showType,
    })
    this.getOrderList();


  },
  getOrderList: function(event) {
    var that = this;
    //获取订单列表
    wx.request({
      url: app.d.hostUrl + '/api/order/getOrderList',
      method: 'post',
      data: {
        'type': that.data.type,
        sessionkey: wx.getStorageSync('sessionkey')
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res);
        var goodslist = res.data.data;
        that.setData({
          goodslist: goodslist,
          isdata: 0,
        });
        if (goodslist == '') {
          that.setData({
            isdata: 1,
          });
        }
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          icon:"none",
          duration: 2000
        });
      },
    });
  },

  switchTab: function(event) {
    let showType = event.currentTarget.dataset.index;
    wx.setStorageSync('showType', showType);
    this.setData({
      type: showType,
      goodslist: []
    });
    this.getOrderList();
  },

  toOrderDetails: function(e) {
    let order = e.currentTarget.dataset.order;
    // wx.setStorageSync('orderId', orderId)
    console.log(order);
    const orderdetail = encodeURIComponent(JSON.stringify(order));
    wx.navigateTo({
      url: '/pages/order_details/index?orderdetail=' + orderdetail,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 拨打电话
  opentel: function () {
    app.gotel();
  },

  /**
 * 用户点击右上角分享
 */
  onShareAppMessage: function () {
    var openid = wx.getStorageSync('openid');
    from: menu;
    return {
      title: '走吧商城',
      path: '/pages/onepage/onepage?openid=' + openid,
      success: function (res) {
        // console.log(openid);      
      },
      fail: function (res) {
        // console.log(res);
      }
    }
  },

})
